

#ifndef _ZK_CFG2_H_
#define _ZK_CFG2_H_

#include <stdint.h>

/*===================================================================*/

enum cfg_id{
	CFG_ID_MANU = 0,
	CFG_ID_USER,
	CFG_ID_MAX
};

enum {
	CFG_BLK_INFO = 0,
	CFG_BLK_APPLE,
	CFG_BLK_GOOGLE,
	CFG_BLK_LEAF,
	CFG_BLK_MAX
};

#pragma pack(1)

typedef struct {
	uint8_t aid[3];
	uint8_t key_id;
	uint8_t key_ver;
	uint8_t key_type;
	uint8_t key_no;
}key_set_t;

typedef struct {
	uint16_t version;
	uint8_t epc[7];
	key_set_t key_sets[2];
	uint8_t file_id;
	uint32_t offset;
	uint32_t length;
	uint8_t fomat;
}cfg_apple_wallet_t;

typedef struct {
	uint16_t version;
	key_set_t key_set;
	uint8_t fid;
	uint8_t df_name[16];
}cfg_google_wallet_t;

typedef struct {
	uint32_t magic;			//魔数
	uint32_t check_sum;		//校验和
	uint32_t update_version;		//每更新一次加1
	uint16_t version;		//版本
	uint8_t verify_code[16];
	cfg_apple_wallet_t aw;
	uint8_t reserve1[16];
	cfg_google_wallet_t gw;
	uint8_t reserve2[16];
	uint8_t reserve3[64];
}cfg_wavelynx_t;

typedef struct {
	uint8_t magic;
	uint8_t check_sum;
	uint8_t data[62];
}cfg_block_t;


typedef struct {
	cfg_block_t blocks[CFG_BLK_MAX];
}cfg_page_t;


#pragma pack()

void cfg_init(void);

void *cfg_get(uint8_t id, uint8_t blk);

int cfg_update(uint8_t id, uint8_t blk, const void* data, uint8_t len);

int cfg_flush(void);



#endif

